#ifndef SINGLETON_H
#define SINGLETON_H

template <typename T>
class Singleton
{
public:
    static T* GetInstance();
    static void Destroy();

protected:
    virtual ~Singleton() {};
    inline explicit Singleton() {}

private:
    static T* m_ptr;
};

template<typename T>
T* Singleton<T>::m_ptr = 0;

template<typename T>
T* Singleton<T>::GetInstance()
{
    if (!Singleton::m_ptr)
    {
        Singleton::m_ptr = new T();
    }

    return Singleton::m_ptr;
}

template<typename T>
void Singleton<T>::Destroy()
{
    if (Singleton::m_ptr)
    {
        delete Singleton::m_ptr;
        Singleton::m_ptr = 0;
    }
}

#endif